/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.istia.gesstages.dao.tests.util;

import fr.istia.gesstages.dao.IDaoApply;
import fr.istia.gesstages.dao.IDaoOffer;
import fr.istia.gesstages.dao.IDaoUser;
import fr.istia.gesstages.dao.IDaoUserType;
import fr.istia.gesstages.jpa.Apply;
import fr.istia.gesstages.jpa.Offer;
import fr.istia.gesstages.jpa.User;
import fr.istia.gesstages.jpa.UserType;
import java.util.Date;

public class DBManager {

    private static boolean ARCHIVED = true;
    private static boolean VISIBLE = true;
    private static boolean ISTIA = true;
    private IDaoOffer daoOffer;
    private IDaoApply daoApply;
    private IDaoUser daoUser;
    private IDaoUserType daoUserType;
    
    public static final int NB_ADMIN = 1;
    public static final int NB_STUDENTS = 3;
    public static final int NB_USERS = 4;
    public static final int NB_USER_TYPES = 3;
    public static final int NB_OFFERS = 4;
    public static final int NB_OFFERS_ARCHIVED = 1;
    public static final int NB_OFFERS_NOT_ARCHIVED = 3;
    public static final int NB_OFFERS_NOT_ATTRIBUTED = 2;
    public static final int NB_APPLIES_FOR_CEDRIC = 2;
    public static final int NB_APPLIES_ARCHIVED_FOR_CEDRIC = 1;
    public static final int NB_APPLIES_FOR_GAETAN = 0;
    public static final int NB_APPLIES = 2;
    
    UserType admin, etudiant, invite;
    User theAdmin, cedric, gaetan, hubert;
    Offer stageSopra, stageCapgemini, stageAtos, stageLogica;

    public DBManager() {
    }
    
    public void deleteEverything(){
        daoApply.deleteAll();
        daoOffer.deleteAll();
        daoUser.deleteAll();
        daoUserType.deleteAll();
    }
    
    public void createUserTypes(){
        admin = daoUserType.create(new UserType("Administrateur"));
        etudiant = daoUserType.create(new UserType("Etudiant"));
        invite = daoUserType.create(new UserType("Invité"));
    }
    
    public void createUsers(){
        theAdmin = daoUser.create(new User(admin, "admin", "21232f297a57a5a743894a0e4a801fc3", "Administrateur", "", "admin@portail-stages.com", false, ""));
        cedric = daoUser.create(new User(etudiant, "cedric.moreau", "5f4dcc3b5aa765d61d8327deb882cf99", "Moreau", "Cédric", "cem.moreau@gmail.com", true, "EI5"));
        gaetan = daoUser.create(new User(etudiant, "gaetan.loussier", "5f4dcc3b5aa765d61d8327deb882cf99", "LOUSSIER", "Gaëtan", "gaetan.loussier@gmail.com", true, "EI5"));
        hubert = daoUser.create(new User(etudiant, "hubert.mong", "5f4dcc3b5aa765d61d8327deb882cf99", "Mong", "Hubert", "hubert2000m@gmail.com", false, "EI5"));
    }
    
    public void createOffers(){
        stageSopra = daoOffer.create(new Offer(
            "Mission : vous serez également amené(e) à étudier, puis à actualiser le panorama des principales offres technologiques du marché (Oracle BRM, Ericsson/BSCS, SAP/Highdeal…) en appréciant leur capacité à adresser les enjeux de cette vision prospective",
            "Stage en développement Java EE",
            "Sopra Group",
            "Direction du Recrutement\r\n9 bis rue de Presbourg",
            "75116",
            "Paris",
            new Date("10/11/2011"),
            new Date("16/11/2011"),
            VISIBLE, ISTIA, theAdmin, "Stage_Sopra.pdf", "Sébastien Délai", !ARCHIVED));
        stageCapgemini = daoOffer.create(new Offer(
            "Etudier et concevoir un système de gestion des offres de stage de l'entreprise",
            "Stage en développement PHP",
            "Capgemini",
            "11 rue de Tilsitt, Place de l'étoile",
            "75017",
            "Paris",
            new Date("20/09/2011"),
            new Date("22/10/2011"),
            VISIBLE, ISTIA, theAdmin, "", "Didier Renaud", ARCHIVED));
        stageAtos = daoOffer.create(new Offer(
            "Dans le cadre de la refonte d’une partie de son SI, le client, une agence leader en location de véhicules, a démarré depuis un an un projet réalisé en méthode Agile Scrum (2 équipes de 7 personnes).",
            "Développement JAVA en équipe Agile H/F",
            "Atos",
            "18 avenue des droits de l'homme",
            "45000",
            "Orléans",
            new Date("11/11/2011"),
            new Date("22/12/2011"),
            VISIBLE, ISTIA, theAdmin, "Stage_Atos.pdf", "Jacques Martin", !ARCHIVED));
        stageLogica = daoOffer.create(new Offer(
            "Dans le cadre de la maintenance d'applications chez un client important de l'assurance, vous développerez des mises à jour sur un projet main-frame.",
            "Développement main-frame H/F",
            "Logica",
            "17 Place des Reflets",
            "92400",
            "Courbevoie",
            new Date("16/11/2011"),
            new Date("19/12/2011"),
            !VISIBLE, ISTIA, theAdmin, "", "Etienne Jouis", !ARCHIVED));
    }
    
    public void createApplies(){
        daoApply.create(new Apply(stageSopra, cedric, new Date()));
        daoApply.create(new Apply(stageCapgemini, cedric, new Date()));
    }

    public void setDaoApply(IDaoApply daoApply) {
        this.daoApply = daoApply;
    }

    public void setDaoOffer(IDaoOffer daoOffer) {
        this.daoOffer = daoOffer;
    }

    public void setDaoUser(IDaoUser daoUser) {
        this.daoUser = daoUser;
    }

    public void setDaoUserType(IDaoUserType daoUserType) {
        this.daoUserType = daoUserType;
    }

    public UserType getAdmin() {
        return admin;
    }

    public User getCedric() {
        return cedric;
    }

    public UserType getEtudiant() {
        return etudiant;
    }

    public User getGaetan() {
        return gaetan;
    }

    public User getHubert() {
        return hubert;
    }

    public UserType getInvite() {
        return invite;
    }

    public Offer getStageAtos() {
        return stageAtos;
    }

    public Offer getStageCapgemini() {
        return stageCapgemini;
    }

    public Offer getStageSopra() {
        return stageSopra;
    }

    public User getTheAdmin() {
        return theAdmin;
    }
}
